package com.itheima.Demo;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class Demo客户端01 {
    public static void main(String[] args) throws IOException {
        //创建对象;
        SocketChannel sc = SocketChannel.open();
        //连接ip和端口
        sc.connect(new InetSocketAddress("192.168.50.113", 1314));
        //创建数组
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        //给数组添加数据
        buffer.put("你好".getBytes());
        //切换
        buffer.flip();
        //输出;
        sc.write(buffer);
        sc.close();
    }
}

